package BinaryTreePackage;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Lzm
 * @version 1.0
 */
public class binaryTreePaths_ {


  @Test
  public void binaryTreePathsTest(){
    List<String> result = new ArrayList<>();
  }

  /*public List<String> binaryTreePaths(TreeNode root) {
    // get the end condition
    if (root == null){

    }
  }*/
  // 前序遍历
  public void backTracking(TreeNode root,List<String> result,List<Integer> path) {
    path.add(root.val);
    // 当遍历到叶子节点时收获结果
    if (root.left == null && root.right == null){
      result.add(transfer(path));
      return;
    }
    // 左
    if (root.left != null){
      backTracking(root.left,result,path);
      path.remove(path.size() - 1);
    }
    // 右
    if (root.right != null){
      backTracking(root.right,result,path);
      path.remove(path.size() - 1);
    }
  }
  // 将path中的数据transfer to value1->value2->value3->....
  public String transfer(List<Integer> path){
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < path.size() - 1; i++) {
      sb.append(path.get(i)).append("->");
    }
    return sb.append(path.get(path.size() - 1)).toString();
  }
}
